<template>
  <div class="xtx-goods-page">
    <div class="container" v-if="goodsInfo">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="'/category/' + goodsInfo.categories[1].id">{{
          goodsInfo.categories[1].name
        }}</XtxBreadItem>
        <XtxBreadItem :to="'/category/sub/' + goodsInfo.categories[0].id">{{
          goodsInfo.categories[0].name
        }}</XtxBreadItem>
        <XtxBreadItem>{{ goodsInfo.name }}</XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <!-- 商品信息 -->
      <div class="goods-info">
        <div class="media">
          <GoodsImage :goodsImage="goodsInfo.mainPictures"></GoodsImage>
          <GoodsSales :goods="goodsInfo"></GoodsSales>
        </div>
        <div class="spec">
          <GoodsName :goods="goodsInfo" />
          <GoodsSku :goods="goodsInfo" @getSkuId="getSkuId" />
          <XtxNumbox label="数量" v-model="num"></XtxNumbox>
          <XtxButton type="primary" style="margin-top:20px;"
            >加入购物车</XtxButton
          >
        </div>
      </div>
      <!-- 商品推荐 -->
      <GoodsRelevant :id="goodsInfo.id" />
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs">
            <GoodsTabs :goods="goodsInfo" />
          </div>
          <!-- 注意事项 -->
          <div class="goods-warn"></div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<script>
// import {} from ''
import GoodsRelevant from './components/goods-relevant'
import GoodsImage from './components/goods-image'
import GoodsSales from './components/goods-sales'
import GoodsName from './components/goods-name'
import GoodsSku from './components/goods-sku'
import GoodsTabs from './components/goods-tabs'
import { Goods } from '@/api/product'
import { ref } from 'vue'
export default {
  name: 'XtxGoodsPage',
  components: {
    GoodsRelevant,
    GoodsImage,
    GoodsSales,
    GoodsName,
    GoodsSku,
    GoodsTabs
  },
  props: {
    id: {
      type: String
    }
  },
  setup (props) {
    // 数据请求
    const goodsInfo = ref('')
    Goods(props.id).then(res => {
      // console.log(res)
      goodsInfo.value = res.result
    })
    // 收到子组件选择的商品
    function getSkuId (obj) {
      console.log(obj)
    }
    // 子组件的数量
    const num = ref(1)
    // console.log(goodsInfo)
    return { goodsInfo, getSkuId, num }
  }
}
</script>

<style scoped lang="less">
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
